package com.zzt.book.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description
 * User: panda
 * Date: 2025-03-29
 * Time: 21:04
 */
@Slf4j
@Aspect
@Component
public class TimeAspect {

    @Around("execution(* com.zzt.book.controller.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint pjp) throws Throwable {
        //1.记录开始时间
        long start = System.currentTimeMillis();
        //2.执行目标方法
        Object proceed = pjp.proceed();
        long end = System.currentTimeMillis();
        log.info(pjp.getSignature() + "耗时：" + (end-start) + "ms");
        return proceed;
    }
}
